//# COMP 355    #  WONG YI CHUN        07017375         eg_wycaa
package com.jimmyapp.papa;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;

import android.os.Bundle;


import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;

import android.view.View.OnTouchListener;
import android.view.WindowManager;

import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher.ViewFactory;

public class Startup extends Activity implements ViewFactory {
	//private TextSwitcher ts;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		this.setContentView(R.layout.main);
		// Display display = ((WindowManager)
		// getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		// int height = display.getHeight();
		//ts = (TextSwitcher)findViewById(R.id.vibTextSwitcher);
		//ts.setFactory(this);
		
		final ImageView iv = (ImageView) findViewById(R.id.startButton);
		// iv.setPadding(0, height/2-iv.getHeight(), 0, 0);
		final Intent intent = new Intent(Startup.this, GameActivity.class);
		
		iv.setOnTouchListener(new OnTouchListener() {
			boolean onUp = false;

			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {

				switch (arg1.getAction()) {
				case MotionEvent.ACTION_DOWN:
					iv.setImageResource(R.drawable.startup_press);
					onUp = true;
					intent.putExtra("vibrate",vibration );
					intent.putExtra("sound",sound);
					Startup.this.startActivity(intent);
					overridePendingTransition(R.anim.fadein,R.anim.fadeout);
					return true;
				case MotionEvent.ACTION_MOVE:
				case MotionEvent.ACTION_OUTSIDE:
					onUp = false;
			
					iv.setImageResource(R.drawable.startup);
					return true;
				case MotionEvent.ACTION_UP:
					if (onUp) {
						return true;
					}
					return false;
				default:
					break;
				}
				return false;
			}

		});

	}
	public static boolean vibration = true; 
	public static boolean sound = true;
	private static final String ON_VIB = "Vibration on";
	private static final String OFF_VIB = "Vibration off";
	private static final String ON_SOUND = "Sound on";
	private static final String OFF_SOUND = "Sound off";
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.game_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		
		switch (item.getItemId()) {
			
			case R.id.vibmenu:	
				vibration = !vibration;		
				Toast.makeText(this, vibration?ON_VIB:OFF_VIB, Toast.LENGTH_SHORT).show();
				
				break;
			case R.id.soundItem:
				sound = !sound;
				Toast.makeText(this, sound?ON_SOUND:OFF_SOUND, Toast.LENGTH_SHORT).show();
				
				break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public View makeView() {
		TextView t = new TextView(this);
        t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
        t.setTextSize(15);
        t.setTextColor(Color.BLACK);
        
        return t;
	}
}